#! /usr/bin/env python
#coding=utf-8
# tgame_entity
import tgame_player
import tgame_map
import tgame_mapmgr

g_builds = {}
g_entitys = {}
g_phys = {}
g_items = {}

ET_Player = 0x01
ET_Zombie = 0x02
ET_Barrier = 0x03
ET_Other = 0x04

def init():
	pass

def addentity(playerinfo, AItype = None):
	import tgame_player_c
	global g_entitys
	entity = tgame_player.TGame_Player(playerinfo, AItype)
	g_entitys[playerinfo.uid] = entity
	g_phys[entity.obj.phy.id] = entity
	return g_entitys[playerinfo.uid]

def delentity(uid = None,id = None):
	if uid:
		# 玩家死亡
		if uid == tgame_mapmgr.inst.objMe.player.uid:
			tgame_mapmgr.inst.playerdead()
			return
		id = g_entitys[uid].obj.phy.id
		g_entitys[uid].destroy()
		g_entitys[uid] = None
		g_phys[id] = None
		del g_entitys[uid]
		del g_phys[id]

	elif id:
		uid = g_phys[id].player.uid
		g_phys[id].destroy()
		g_entitys[uid] = None
		g_phys[id] = None
		del g_entitys[uid]
		del g_phys[id]

def destroy():
	import copy
	copyg_e = copy.copy(g_entitys)
	for key in copyg_e:
		id = g_entitys[key].obj.phy.id
		g_entitys[key].destroy()
		del g_entitys[key]
		del g_phys[id]
	pass

def update():
	for entity in g_entitys:
		g_entitys[entity].update()